package trinnes.oliver.unimaas.smartpentalath.control;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import trinnes.oliver.unimaas.smartpentalath.data.Piece;
import trinnes.oliver.unimaas.smartpentalath.intelligence.Evaluation;
import trinnes.oliver.unimaas.smartpentalath.intelligence.Search;
import trinnes.oliver.unimaas.smartpentalath.intelligence.features.CaptureFeature;
import trinnes.oliver.unimaas.smartpentalath.intelligence.features.CenterFeature;
import trinnes.oliver.unimaas.smartpentalath.intelligence.features.FourWithFreedomFeature;
import trinnes.oliver.unimaas.smartpentalath.intelligence.features.GroupFeature;
import trinnes.oliver.unimaas.smartpentalath.intelligence.features.MaxRowFeature;
import trinnes.oliver.unimaas.smartpentalath.intelligence.features.RandomFeature;
import trinnes.oliver.unimaas.smartpentalath.intelligence.features.VictoryFeature;

/**
 * Can be used to test the SmartPlayer against a different AI
 * @author Oliver Trinnes
 */
public class TestPlayer extends Player implements PropertyChangeListener
{
  private Evaluation evaluation;

  public TestPlayer(Game game, Piece piece, String name, int ID)
  {
    super(game, piece, name, ID);
    evaluation = new Evaluation();
    evaluation.addFeature(new VictoryFeature(Evaluation.INFINITY));
    evaluation.addFeature(new CaptureFeature(1000));
    evaluation.addFeature(new MaxRowFeature(15));
    evaluation.addFeature(new CenterFeature(10));
    evaluation.addFeature(new FourWithFreedomFeature(100));
    evaluation.addFeature(new GroupFeature(100));
    evaluation.addFeature(new RandomFeature(1, 10));
  }

  @Override
  public int getNextMove()
  {
    Game copyGame = new Game(game);
    Search search = new Search(evaluation);
    search.addPropertyChangeListener(this);
    return search.findMaxMove(copyGame, this);
  }

  public void propertyChange(PropertyChangeEvent evt)
  {
    if (evt.getPropertyName().equals("new_time_left"))
      changeSupport.firePropertyChange("new_progress", evt.getOldValue(), evt.getNewValue());
  }
}
